﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Jy123.DBUtility;

namespace Jy123.BLL.User_Module
{
    /// <summary>
    /// 业务逻辑类User_Venues 的摘要说明。
    /// </summary>
    public class User_Venues
    {
        public User_Venues()
        { }
        #region  成员方法

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Jy123.Model.User_Module.User_Venues> GetModelList(string strWhere)
        {
            DataSet ds = GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }

        private DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,VName,Logo,VStatus,FUser,FJType,FLevel,FColor,RaceTimes,Description,Assets,Vitality,RaceClub,Cash,UserName,UID ");
            strSql.Append(" FROM User_Venues ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 返回好友的同类型组件
        /// </summary>
        /// <param name="FJType">组件类型</param>
        /// <param name="order">排序</param>
        /// <param name="userId">用户id</param>
        /// <returns>好友的同类型组件</returns>
        public List<Jy123.Model.User_Module.User_Venues> GetFriendModelList(int FJType, string order, int userId)
        {
            StringBuilder strWhere = new StringBuilder();
            strWhere.AppendFormat("FJType = {0} ", FJType);
            strWhere.Append("AND FUser IN (");
            strWhere.Append("SELECT FFriend FROM User_Friend ");
            strWhere.AppendFormat("WHERE FUser = {0})", userId);
            if (!string.IsNullOrEmpty(order))
            {
                strWhere.Append(" ORDER BY " + order);
            }
            return GetModelList(strWhere.ToString());
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Jy123.Model.User_Module.User_Venues> DataTableToList(DataTable dt)
        {
            List<Jy123.Model.User_Module.User_Venues> modelList = new List<Jy123.Model.User_Module.User_Venues>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Jy123.Model.User_Module.User_Venues model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Jy123.Model.User_Module.User_Venues();
                    if (dt.Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(dt.Rows[n]["ID"].ToString());
                    }
                    model.VName = dt.Rows[n]["VName"].ToString();
                    model.Logo = dt.Rows[n]["Logo"].ToString();
                    if (dt.Rows[n]["VStatus"].ToString() != "")
                    {
                        model.VStatus = int.Parse(dt.Rows[n]["VStatus"].ToString());
                    }
                    if (dt.Rows[n]["FUser"].ToString() != "")
                    {
                        model.FUser = int.Parse(dt.Rows[n]["FUser"].ToString());
                    }
                    if (dt.Rows[n]["FJType"].ToString() != "")
                    {
                        model.FJType = int.Parse(dt.Rows[n]["FJType"].ToString());
                    }
                    if (dt.Rows[n]["FLevel"].ToString() != "")
                    {
                        model.FLevel = int.Parse(dt.Rows[n]["FLevel"].ToString());
                    }
                    if (dt.Rows[n]["FColor"].ToString() != "")
                    {
                        model.FColor = int.Parse(dt.Rows[n]["FColor"].ToString());
                    }
                    if (dt.Rows[n]["RaceTimes"].ToString() != "")
                    {
                        model.RaceTimes = int.Parse(dt.Rows[n]["RaceTimes"].ToString());
                    }
                    model.Description = dt.Rows[n]["Description"].ToString();
                    if (dt.Rows[n]["Assets"].ToString() != "")
                    {
                        model.Assets = decimal.Parse(dt.Rows[n]["Assets"].ToString());
                    }
                    if (dt.Rows[n]["Vitality"].ToString() != "")
                    {
                        model.Vitality = int.Parse(dt.Rows[n]["Vitality"].ToString());
                    }
                    model.RaceClub = dt.Rows[n]["RaceClub"].ToString();
                    if (dt.Rows[n]["Cash"].ToString() != "")
                    {
                        model.Cash = int.Parse(dt.Rows[n]["Cash"].ToString());
                    }
                    model.UserName = dt.Rows[n]["UserName"].ToString();
                    if (dt.Rows[n]["UID"].ToString() != "")
                    {
                        model.UID = int.Parse(dt.Rows[n]["UID"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }
        #endregion  成员方法
    }
}
